<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="提现状态">
              <a-select placeholder="请选择" v-model="queryParam.withdrawStatus">
                <a-select-option :value="item.val" v-for="item in withDrawStatus" :key="item.key">{{
                  item.name
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="submitQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <s-table :columns="columns" :data="loadData" ref="table">
      <span slot="withdrawType" slot-scope="text">
        {{ text | withdrawTypeFilter }}
      </span>

      <span
        slot="withdrawStatus"
        slot-scope="withdrawStatusTxt, record"
        :class="record.withdrawStatus == 2 ? 'txt-succ' : record.withdrawStatus == 1 ? 'txt-default' : 'txt-err'"
      >
        {{ withdrawStatusTxt | withdrawStatusFilter }}
      </span>

      <span slot="createTime" slot-scope="text, record">
        {{ record.updateTime || record.createTime }}
      </span>
    </s-table>
  </a-card>
</template>

<script>
import STable from '@/components/table/'
import Dict from '@/config/dict.conf'
import { getWithdrawList } from '@/api/api'
import { pageQueryConvert } from '@/utils/util'

export default {
  name: 'CheckRecordsList',
  components: {
    STable
  },
  data() {
    return {
      withDrawStatus: Dict.withDrawStatus,

      //过滤条件
      isorter: {
        column: 'createTime',
        order: 'desc'
      },

      // 查询参数
      queryParam: {},

      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'id'
        },
        {
          title: '结算方式',
          dataIndex: 'withdrawType',
          scopedSlots: { customRender: 'withdrawType' }
        },
        {
          title: '结算金额',
          dataIndex: 'withdrawMoney',
          customRender: text => '￥' + text
        },
        {
          title: '收款人',
          dataIndex: 'payeeName'
        },
        {
          title: '开户行',
          dataIndex: 'bankName'
        },
        {
          title: '收款账号',
          dataIndex: 'payeeAct'
        },
        {
          title: '提现状态',
          dataIndex: 'withdrawStatus',
          scopedSlots: { customRender: 'withdrawStatus' }
        },
        {
          title: '处理时间',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        let params = Object.assign({}, parameter, this.queryParam, this.isorter)

        for (let p in params) {
          if (params[p] == -1 || params[p] == '-1') params[p] = undefined
        }

        return getWithdrawList(params).then(res => {
          return pageQueryConvert(res)
        })
      }
    }
  },
  filters: {
    withdrawTypeFilter(checkWay) {
      let withDrawType = Dict.withDrawType || []
      let txt = ''
      for (let c in withDrawType) {
        let wt = withDrawType[c]
        if (wt.val == checkWay) {
          txt = wt.name
          break
        }
      }
      return txt
    },

    withdrawStatusFilter(withdrawStatus) {
      let withdrawStatusList = Dict.withDrawStatus || []
      let txt = ''
      for (let p in withdrawStatusList) {
        let pw = withdrawStatusList[p]
        if (pw.val == withdrawStatus) {
          txt = pw.name
          break
        }
      }
      return txt
    }
  },
  created() {},
  methods: {
    /**
     * 主动查询
     */
    submitQuery(e) {
      let paramsKeyList = Object.keys(this.queryParam)

      if (paramsKeyList.length == 0) {
        this.$message.warning('查询条件不能全为空')
        return
      }

      let params = Object.assign({}, { current: 1, pageSize: 10 }, this.isorter)
      this.$refs.table.loadData(params, {}, null)
    },

    resetSearchForm() {
      this.queryParam = {}
      // this.createTimeArr = []
    }
  }
}
</script>
<style scoped lang="scss">
.txt-succ {
  color: #82ae7a;
}
.txt-default {
  color: #1890ff;
}
.txt-err {
  color: #d80000;
}
</style>
